package QueueUse;/*
 *
 *@author:    Xavier
 *@data:      2023 - 08 - 18
 *@time:      14:55
 *
 */

import java.util.List;

public class MyQueue {
    static class ListNode {
        public int val;
        public ListNode next;

        public ListNode(int val) {
            this.val = val;
        }

    }

    public ListNode head;
    public ListNode last;

    public int usedSize;

    public void offer(int val) {
        ListNode node = new ListNode(val);
        if (head == null) {
            head = node;
            last = node;
        }else {
            head.next = node;
            last = last.next;
        }
        usedSize++;
    }

    public int getUseSize() {
        return usedSize;
    }

    public int poll(){
        if (head == null) {
            return -1;
        }
        int val = -1;
        if (head.next == null) {
            val = head.val;
            head = null;
            last = null;
            return val;
        }
        val = head.val;
        head = head.next;
        usedSize--;
        return val;
    }

    public int peek() {
        if (head == null) {
            return -1;
        }

        return head.val;
    }





}
